﻿@{
    TempData["subMenu-check"] = new string[] { "Public", "ManageUserImpeachReport" };
    ViewData["Title"] = new string[] { "举报管理" };
    var isDisposed = ViewData.Get<List<SelectListItem>>("isDisposed", new List<SelectListItem>());
}
<div class="row tn-page-heading tn-mb-10">
    <div class="col-lg-12">
        <h3>用户举报</h3>
    </div>
</div>
@Styles.Render("~/Bundle/Styles/daterangepicker")
<div class="panel panel-default">
    <div class="panel-body">
        <div id="searchDiv" class="form-inline tn-tool-column">
            <div class="form-group">
                <a class="btn btn-default handle" data-isDisposed="true" href="javascript:;"><i class="fa fa-check"></i> 标识为已处理</a>
            </div>
            <div class="form-group">
                <a class="btn btn-default delete" data-isapproved="true" href="javascript:;"><i class="fa fa-trash"></i> 删除</a>
            </div>
            <div style="float:right;clear:both;">
                <div class="form-group">
                    处理状态: @Html.DropDownList("isDisposed", isDisposed, new { @class = "form-control searchPara", @style = "width:250px" })
                </div>
                <div class="form-group has-feedback">
                    发布时间: @Html.DateTimePicker("Daterangepicker", null, Request.QueryString.Get("minDate", string.Empty), Request.QueryString.Get("maxDate", string.Empty), true)
                    <span class="form-control-feedback"><i class="fa fa-calendar"></i></span>
                </div>
                <div class="form-group">
                    <button class="btn btn-primary" id="search" type="button">搜索</button>
                </div>
            </div>
        </div>     
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body">
        <div id="_ListImpeachReports">
            @Html.Action("_ListImpeachReport", "ControlPanel", new { isDisposed =false})
        </div>
    </div>
</div>
<script>
    require(["jquery", 'tnlayer', 'page', 'datepicker'], function ($, tnlayer) {
        //搜索
        $("#search").click(function () {
            var isDisposed = $(".searchPara").val();
            var startTtime = $("#minDate").val();
            var endTtime = $("#maxDate").val();
           
            $.get('@CachedUrlHelper.Action("_ListImpeachReport", "ControlPanel")?t=' + new Date().getTime(), { 'isDisposed': isDisposed, 'startTtime': startTtime, 'endTtime': endTtime, "pageSize": 20, "pageIndex": 1 }, function (data) {
                $("#_ListImpeachReports").html(data);
            });
        });

        //标识未已处理
        $(document).on("click", '.handle', function () {
            var $this = $(this);
            var $checkboxs = $(".tn-checkbox:checked");
            if ($checkboxs.length) {
                var reportIds = [];
                $checkboxs.each(function () {
                    reportIds.push($(this).data('id'));
                });
                $.post('@CachedUrlHelper.Action("UpdateDisposedStatus", "ControlPanel")', { 'reportIds': reportIds, t: (new Date()).getTime() }, function (data) {
                    if (data.MessageType == 1) {
                        layer.msg(data.MessageContent, { icon: 1 });
                        Search();
                    }
                    else {
                        layer.msg(data.MessageContent, { icon: 2 });
                    }
                });
            }
            else {
                layer.msg("请至少选择一项", { icon: 2 });
            }
        });

        //删除
        $(document).on('click', '.delete', function () {
            var $checkboxs = $(".tn-checkbox:checked");
            if ($checkboxs.length) {
                layer.confirm('确定要删除么?',{ btn: ['确定', '取消'], icon: 3 }, function () {
                        var reportIds = [];
                        $('input[name="checks"]:checked').each(function () {
                            reportIds.push($(this).data('id'));
                        });                       
                        $.post('@CachedUrlHelper.Action("DeleteReports", "ControlPanel")', { 'reportIds': reportIds, t: (new Date()).getTime() }, function (data) {
                            if (data.MessageType == 1) {
                                layer.msg(data.MessageContent, { icon: 1 });

                                Search();
                             
                            }
                            else {
                                layer.msg(data.MessageContent, { icon: 2 });
                            }
                        });
                    });
            }
            else {
                layer.msg('请至少选择一项', { icon: 2 });
            }
        });



        function  Search() {
            var isDisposed = $(".searchPara").val();
            var startTtime = $("#minDate").val();
            var endTtime = $("#maxDate").val();
            var ListImpeachReportPageIndex = $("#ListImpeachReportPageIndex").val();
           
            $.get('@CachedUrlHelper.Action("_ListImpeachReport", "ControlPanel")?t=' + new Date().getTime(), { 'isDisposed': isDisposed, 'startTtime': startTtime, 'endTtime': endTtime, "pageSize":20,"pageIndex": ListImpeachReportPageIndex }, function (data) {
                $("#_ListImpeachReports").html(data);
            });
        };
    })
</script>